function grille_machine(scene) {
	this.scene = scene;
	var that = this;
	this.machine = new THREE.Object3D();
	this.clock = new THREE.Clock();
	this.createMachine();
}

grille_machine.prototype = {

	setPosition: function(x, y, z) {
		this.machine.position.set(x, y, z)
	},

	addPool: function() {
		var wall_material = new THREE.MeshBasicMaterial({
			color: 0x00ff00
		});

		var left_wall = new THREE.BoxGeometry(2, 7, 24);
		var left_cube = new THREE.Mesh(left_wall, wall_material);
		left_cube.position.x = -6;
		this.machine.add(left_cube);

		var right_wall = new THREE.BoxGeometry(2, 7, 24);
		var right_cube = new THREE.Mesh(left_wall, wall_material);
		right_cube.position.x = 6;
		this.machine.add(right_cube);

		var front_wall = new THREE.BoxGeometry(10, 7, 1);
		var front_cube = new THREE.Mesh(front_wall, wall_material);
		front_cube.position.z = -11;
		this.machine.add(front_cube);

		var behind_wall = new THREE.BoxGeometry(10, 7, 1);
		var behind_cube = new THREE.Mesh(behind_wall, wall_material);
		behind_cube.position.z = 11;
		this.machine.add(behind_cube);

		//		var bottom_wall = new THREE.BoxGeometry(10, 1, 21);
		//		var bottom_cube = new THREE.Mesh(bottom_wall, wall_material);
		//		bottom_cube.position.y = -3;
		//		this.machine.add(bottom_cube);

		// ground
		var groundGeometry = new THREE.BoxGeometry(10, 1, 21);
		var groundMaterial = new THREE.MeshStandardMaterial({
			roughness: 0.8,
			metalness: 0.4
		});
		var ground = new THREE.Mesh(groundGeometry, groundMaterial);
		ground.position.y = -3;
		this.machine.add(ground);
		var textureLoader = new THREE.TextureLoader();
		textureLoader.load('textures/hardwood2_diffuse.jpg', function(map) {
			map.wrapS = THREE.RepeatWrapping;
			map.wrapT = THREE.RepeatWrapping;
			map.anisotropy = 16;
			map.repeat.set(4, 4);
			groundMaterial.map = map;
			groundMaterial.needsUpdate = true;
		});

		//顶部透明的box
		var top_texture = new THREE.Texture();
//		top_texture.format = THREE.AlphaFormat;
		top_texture.transparent = 1;
		top_texture.opacity = 0;
		var top_wall = new THREE.BoxGeometry(10, 7, 21);
		var top_material = new THREE.MeshBasicMaterial({
			alphaMap: top_texture
		});
		top_material.wireframe=true;
		var top_mesh = new THREE.Mesh(top_wall, top_material);
		top_mesh.position.y = -1;
		this.machine.add(top_mesh);
	},

	addMachine: function() {
		//左右的格栅
		var output_material = new THREE.MeshBasicMaterial({
			color: new THREE.Color("rgb(255, 0, 0)")
		});

		var left_output = new THREE.BoxGeometry(1, 2, 14);
		var left_cube = new THREE.Mesh(left_output, output_material);
		left_cube.position.set(-4, 4, 4);
		left_cube.rotation.set(-70, 0, 0);
		this.machine.add(left_cube);

		var right_output = new THREE.BoxGeometry(1, 2, 14);
		var right_cube = new THREE.Mesh(left_output, output_material);
		right_cube.position.set(4, 4, 4);
		right_cube.rotation.set(-70, 0, 0);
		this.machine.add(right_cube);

		//栅格网
		var gridLoader = new THREE.TextureLoader().load("textures/grid.jpg");
		gridLoader.wrapS = gridLoader.wrapT = THREE.RepeatWrapping;
		var gridGeometry = new THREE.PlaneBufferGeometry(12, 20);
		var gridMaterial = new THREE.MeshBasicMaterial({
			map: gridLoader
		});
		var grid = new THREE.Mesh(gridGeometry, gridMaterial);

		var params = {
			color: '#ffffff',
			scale: 1,
			flowX: 1,
			flowY: 2
		};
		//		var gridGeometry = new THREE.PlaneBufferGeometry(12, 20);
		//		grid = new THREE.Flow(gridGeometry, {
		//			color: params.color,
		//			scale: params.scale,
		//			flowDirection: new THREE.Vector2(params.flowX, params.flowY),
		//			textureWidth: 512,
		//			textureHeight: 512,
		//			normalMap0: new THREE.TextureLoader().load('textures/grid.jpg', function(texture) {
		//				texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
		//			}),
		//			normalMap1: new THREE.TextureLoader().load('textures/grid.jpg', function(texture) {
		//				texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
		//			}),
		//		});
		grid.position.y = 10;
		grid.rotation.x = Math.PI * -0.5;
		this.machine.add(grid);
		this.updateFlow(grid);
	},

	updateFlow: function(grid) {

	},

	createWater: function() {
		var params = {
			color: '#ffffff',
			scale: 1,
			flowX: 1,
			flowY: 2
		};
		var waterGeometry = new THREE.PlaneBufferGeometry(12, 20);
		water = new THREE.Water(waterGeometry, {
			color: params.color,
			scale: params.scale,
			flowDirection: new THREE.Vector2(params.flowX, params.flowY),
			textureWidth: 512,
			textureHeight: 512,
			clipBias: 1,
			normalMap0: new THREE.TextureLoader().load('textures/grid.jpg', function(texture) {
				texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
			}),
			normalMap1: new THREE.TextureLoader().load('textures/grid.jpg', function(texture) {
				texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
			}),
		});
		//		water = new THREE.Water(
		//			waterGeometry, {
		//				textureWidth: 512,
		//				textureHeight: 512,
		//				waterNormals: new THREE.TextureLoader().load('textures/grid.jpg', function(texture) {
		//					texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
		//				}),
		//				size: 0.1,
		//				alpha: 1.0,
		//				sunColor: 0xffffff,
		//				waterColor: 0x001e0f,
		//				distortionScale: 3.7,
		//				fog: scene.fog !== undefined
		//			}
		//		);
		water.position.y = 1;
		water.rotation.x = Math.PI * -0.5;
		this.machine.add(water);
	},

	createLight: function() {
		var ambientLight = new THREE.AmbientLight(0xcccccc, 0.4);
		this.machine.add(ambientLight);
		var directionalLight = new THREE.DirectionalLight(0xffffff, 0.6);
		directionalLight.position.set(-1, 1, 1);
		this.machine.add(directionalLight);
	},

	createMachine: function() {
		this.addPool();
		this.addMachine();
		this.setPosition(1, -2, 1);
		this.scene.add(this.machine);
		this.createWater();
		this.createLight();
	},

}